<?php
/*
Template Name: Venue Search Result
Auther: Naseer Ahnad
Created: 18-03-2012
*/
get_header(); 


function get_category_id($cat_name){
	$term = get_term_by('name', $cat_name, 'category');
	return $term->term_id;
}

/////// get all parents of specifc area
$parentCatList = get_category_parents($_POST['county'],false,',');
$parentCatListArray = split(",",$parentCatList);
if(count($parentCatListArray)>0) array_shift($parentCatListArray);		///////// removing top most category i-e Countries
$areaID=array();
foreach($parentCatListArray as $pCat){
	if(trim($pCat)!="") $areaID[]=get_category_id(trim($pCat));
}

////////// adding filter for title search
add_filter( 'posts_where' , 'posts_where' );
function posts_where( $where ) {
	$where .= " AND post_title LIKE '%".$_POST['venueName']."%'";
	return $where;
}


$typeID = array(6, $_POST['venueType']);
query_posts(array('category__and'=> $typeID, 'category__in'=> $areaID));


?>
	
    <div class="main-content-inner global-width">
    	
    	<section class="contents full-width">
        
        	<?php if ( have_posts() ) : ?>

				<h1><?php printf( __( 'Search Results for: Venues', 'twentyeleven' ), '<span>' . get_search_query() . '</span>' ); ?></h1>


				<ul class="search-results">
					<?php /* Start the Loop */ ?>
					<?php while ( have_posts() ) : the_post(); ?>
					                
						<li>

						<?php if(has_post_thumbnail($post->ID )) {
                              	$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); 
								$image = $image[0];
							  }
							  else
							  	$image="http://armchairweddingguru.co.uk/wp-content/uploads/2012/03/img.gif";
						?>
						<a href="<?php the_permalink(); ?>"><img src="<?php echo $image;?>" alt="Image" class="float-left"></a>
							<p class="bold"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
							<p><?php the_excerpt(); ?></p>
                            <a class="button" href="<?php the_permalink(); ?>">Detail</a>
                            <div class="clearfix"></div>
						</li>
					    
					<?php endwhile; ?>
                </ul>
                
                <?php else : ?>

				<h1><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>

				<p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'twentyeleven' ); ?></p>
				<article class="search one-third search-page"><?php get_search_form(); ?></article>

			<?php endif; ?>
    		
    	</section>   
    	     
    	<div class="clearfix"></div>
    </div>
 

<!-- Main Content Ends -->
</section>

<?php get_footer(); ?>